
const fs = require('fs');
const path = require('path');

exports.searchFile = function (query, data) {
    data.forEach(file => {
        if (file.name.includes(query)) {
            console.log(file);
        }
    });
}

//遍历目录
function fileTraversal(filePath, data) {
    fs.readdir(filePath, (err, files) => {
        if (err) {
            console.error(err);
            return;
        }
        files.forEach(file => {
            const cPath = filePath + '/' + file;
            fs.stat(cPath, (err, stats) => {
                if (err) {
                    console.error(err);
                    return;
                }
                if (stats.isFile()) {
                    data.push(path.parse(cPath));
                    console.log(path.parse(cPath));
                } else if (stats.isDirectory()) {
                    fileTraversal(cPath, data);
                }
            });
        });
    });
}
exports.fileTraversal = fileTraversal;






// fileTraversal('g:\\code\\node\\node2024\\DOM');
// console.log('++++++++++++++++++++++++++++：');
// searchFile('留言板');